// 准备路由
// import App from '@/views/App';
// import Fast from '@/views/Fast';
// import Home from '@/views/Home';
// import Login from '@/views/Login';
// import Mine from '@/views/Mine';
// import Practice from '@/views/Practice';
// import Select from '@/views/Select';
// import Subjects from '@/views/Subjects';
import { createHashRouter as createRouter, redirect } from 'react-router-dom'
// 通过 lazy 这个函数进行组件的异步加载
import { lazy } from 'react';
const Home = lazy(() => import('@/views/Home'))
const Fast = lazy(() => import('@/views/Fast'))
const Mine = lazy(() => import('@/views/Mine'))
const Practice = lazy(() => import('@/views/Practice'))
const Select = lazy(() => import('@/views/Select'))
const Subjects = lazy(() => import('@/views/Subjects'))
const Login = lazy(() => import('@/views/Login'))
const App = lazy(() => import('@/views/App'))


const router = createRouter([
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/',
    element: <App />,
    // 如果使用 react-router-dom 自带的 loader 实现路由拦截，需要的东西比较，也写起来比较麻烦
    // loader({ request }) {
    //   // console.log(params)
    //   // 判断 当前是否已经登录
    //   let token = localStorage.getItem('token')
    //   if (token) {
    //     // console.log(request.url.substring(21))
    //     let path = request.url.substring(21)
    //     if (path == '/') {
    //       return redirect('/home')
    //     }
    //     return true;// 代表校验通过        
    //   } else {
    //     // 跳转到登录页
    //     return redirect('/login')
    //   }
    // },
    children: [
      // 实现重定向的方式1：在 配置表里面加上 index 属性 ，但是不是特别推荐
      // { index: true, element: <Home /> },
      { path: 'home', element: <Home /> },
      { path: 'fast', element: <Fast /> },
      { path: 'mine', element: <Mine /> },
      { path: 'select/:actionCode', element: <Select /> },
      { path: 'practice', element: <Practice /> },
      { path: 'subjects', element: <Subjects /> },
    ]
  }
]);


export default router;